<?php
require_once('includes/config.php');
require_once('includes/sessions.php');

$stat = $db -> Execute("SELECT page, id FROM players WHERE email='".$_SESSION['email']."'");
if ($stat -> fields['miejsce'] != 'Rozmowa') 
{
$db -> Execute("UPDATE players SET page='Rozmowa' WHERE email='".$_SESSION['email']."'");
}

$chat = $db -> SelectLimit("SELECT chat, user, czas, senderid, ownerid FROM priv WHERE ownerid=".$stat -> fields['id']." OR senderid=".$stat -> fields['id']." ORDER BY id DESC", 25);
$e = $chat -> RecordCount();

$arrtext = array();
$arrauthor = array();
$arrsenderid = array();
$arrczas = array();
$i = $e-1;
while (!$chat -> EOF) 
{
    $text = wordwrap($chat -> fields['chat'],50,"\n",1);
	$arrtext[$i] = $text;
	$arrauthor[$i] = $chat -> fields['user'];
	$arrczas[$i] = $chat -> fields['czas'];
	if ($chat -> fields['ownerid'] != $stat -> fields['id']) 
	{
	$arrsenderid[$i] = "do <a href=priv.php?to=".$chat -> fields['ownerid'].">".$chat -> fields['ownerid']."</a>";
	} else {
	$arrsenderid[$i] = "od <a href=priv.php?to=".$chat -> fields['senderid'].">".$chat -> fields['senderid']."</a>";
	}	
	$arrownerid[$i] = $chat -> fields['ownerid'];
	$chat -> MoveNext();
	$i = $i - 1;
}
$chat -> Close();
$d = 0;
while ($d < $e)
{
	echo $arrczas[$d].' <b>'.$arrauthor[$d].'</b> '.$arrsenderid[$d].': '.$arrtext[$d].'<br>';
	$d = $d + 1;
}
$stat -> Close();


?>
